﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Table = FCNS.Data.Table;
using DoubleH.Utility;
using System.Diagnostics;

namespace AfterSaleServiceS
{
    /// <summary>
    /// PaiDan.xaml 的交互逻辑
    /// </summary>
    public partial class XiaDan : Window
    {
        Table.AfterSaleServiceS order = null;

        public XiaDan(Table.AfterSaleServiceS ass)
        {
            InitializeComponent();

            order = ass;
            InitVar();
            InitEvent();
        }

        private void InitVar()
        {
            dateTimePickerXiaDanDateTime.Value = DateTime.Now;

            checkComboBox1.DisplayMemberPath = "Name";
            checkComboBox1.SelectedMemberPath = "Id";
            checkComboBox1.ValueMemberPath = "Id";
            checkComboBox1.ItemsSource = Table.UserS.GetList(Table.UserS.EnumEnable.启用, Table.UserS.EnumFlag.操作员, Table.UserS.EnumFlag.经办人);

            textBoxGuanLianDanHao.Text = order.GuanLianDanHao;
            checkBoxFirst.IsChecked = order.First;
            checkBoxFirst.Visibility = order.First ? Visibility.Visible : Visibility.Hidden;
        }

        private void InitEvent()
        {
            buttonOk.Click += (ss, ee) =>
            {
                if (checkComboBox1.SelectedItems.Count == 0)
                {
                    MessageWindow.Show("请选择执行工程师");
                    return;
                }
                order.PaiDanDateTime = (DateTime)dateTimePickerXiaDanDateTime.Value;
                order.GuanLianDanHao = textBoxGuanLianDanHao.Text;

                //StringBuilder sb = new StringBuilder();
                //foreach (object o in checkComboBox1.SelectedItems)
                //    sb.Append(((Table.UserS)o).Id + ";");

                //sb.Remove(sb.Length - 1, 1);
                order.ServiceUserS = checkComboBox1.SelectedValue;

                Table.DataTableS.EnumDatabaseStatus result = order.UpdateToNext();
                if (result == Table.DataTableS.EnumDatabaseStatus.操作成功)
                    this.Close();
                else
                    MessageWindow.Show(result.ToString());
            };
        }
    }
}
